<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateRechargesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('recharges', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('user_id')->comment('用户ID');
            $table->unsignedInteger('coin_id')->comment('币种ID');
            $table->string('hash')->comment('区块链交易ID');
            $table->unsignedDecimal('number', 20, 8)->comment('充值数量');
            $table->string('address')->comment('充值地址');
            $table->string('tag')->nullable()->default(null)->comment('地址标签');
            $table->unsignedTinyInteger('status')->nullable()->default(1)->comment('充值状态: 0:未到账 1:已到账');
            $table->timestamp('created_at')->nullable()->useCurrent()->comment('充值时间');
            $table->timestamp('updated_at')->nullable()->useCurrent()->comment('到账时间');

            $table->unique(['coin_id', 'hash']);
            $table->index('address');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('recharges');
    }
}
